﻿using System;
using System.Web;

namespace Actya.Web.Infrastructure
{
	public static class UrlUtil
	{
		public static string GetHostUrlFromRequest(HttpRequestBase request)
		{
			if (request == null)
			{
				throw new ArgumentNullException("request", "Request cannot be null");
			}
			return String.Format("{0}://{1}{2}{3}"
			                     , request.Url.Scheme
			                     , request.Url.Host
			                     , request.Url.Port != 80 ? ":" + request.Url.Port : String.Empty
			                     , request.ApplicationPath != "/" ? request.ApplicationPath : String.Empty);
		}
	}
}